/**
 * Created on Tue Mar 01 22:16:04 CST 2011
 * Copyright SinoBest, 2010-2011, All rights reserved.
 */package cn.com.test.dao;

import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.com.test.dao.Problem;


/**
 * @Author zhou
 * @Date Tue Mar 01 22:16:04 CST 2011
 * @to-do 
 */public class ProblemDAO extends HibernateDaoSupport {
	
	private static final Log log = LogFactory.getLog(ProblemDAO.class);
	
	// property constants
	public static final String SYSTEMID = "systemid";
	public static final String TITLE = "title";
	public static final String GAME = "game";
	public static final String AERA = "aera";
	public static final String USERNAME = "username";
	public static final String NICKNAME = "nickname";
	public static final String TIME = "time";
	public static final String LINK = "link";
	public static final String WTLX = "wtlx";
	public static final String WTJJQD = "wtjjqd";
	public static final String CONTENT = "content";
	public static final String STATE = "state";
	public static final String CREATOR = "creator";
	public static final String CREATETIME = "createtime";
	
	// property constants
	protected void initDao() {
		// do nothing
	}
	
	public void save(Problem transientInstance) {
		log.debug("saving Problem instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}
	
	public void delete(Problem persistentInstance) {
		log.debug("deleting Problem instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}
	
	public Problem findById(java.lang.String id) {
		log.debug("getting Problem instance with id: " + id);
		try {
			Problem instance = (Problem) getHibernateTemplate().get(
					"cn.com.test.dao.Problem", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}
	
	public List findAll() {
		log.debug("finding all Problem instances");
		try {
			String queryString = "from Problem";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
	public Problem merge(Problem detachedInstance) {
		log.debug("merging Problem instance");
		try {
			Problem result = (Problem) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}
	
	public void attachDirty(Problem instance) {
		log.debug("attaching dirty Problem instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Problem instance) {
		log.debug("attaching clean Problem instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static ProblemDAO getFromApplicationContext(ApplicationContext ctx) {
		return (ProblemDAO) ctx.getBean("ProblemDAO");
	}
	
	public List findByExample(Problem instance) {
		log.debug("finding Problem instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: " + results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}
	
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Problem instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Problem as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
	
	public List findBySystemid(Object systemid) {
		return findByProperty(SYSTEMID, systemid);
	}
	public List findByTitle(Object title) {
		return findByProperty(TITLE, title);
	}
	public List findByGame(Object game) {
		return findByProperty(GAME, game);
	}
	public List findByAera(Object aera) {
		return findByProperty(AERA, aera);
	}
	public List findByUsername(Object username) {
		return findByProperty(USERNAME, username);
	}
	public List findByNickname(Object nickname) {
		return findByProperty(NICKNAME, nickname);
	}
	public List findByTime(Object time) {
		return findByProperty(TIME, time);
	}
	public List findByLink(Object link) {
		return findByProperty(LINK, link);
	}
	public List findByWtlx(Object wtlx) {
		return findByProperty(WTLX, wtlx);
	}
	public List findByWtjjqd(Object wtjjqd) {
		return findByProperty(WTJJQD, wtjjqd);
	}
	public List findByContent(Object content) {
		return findByProperty(CONTENT, content);
	}
	public List findByState(Object state) {
		return findByProperty(STATE, state);
	}
	public List findByCreator(Object creator) {
		return findByProperty(CREATOR, creator);
	}
	public List findByCreatetime(Object createtime) {
		return findByProperty(CREATETIME, createtime);
	}

}